package educar.Carrera;
import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JOptionPane;

import educar.Carrera.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import educar.materia.*;
import educar.facultad.*;

public class CrearCarreraMediador implements ActionListener {
	private CrearCarreraVentana view =new CrearCarreraVentana();


	public CrearCarreraMediador(){
		view.setVisible(true);
		view.addActionListener(this);
	}
	
	public void actionPerformed(ActionEvent e) {
		Object obj = e.getSource();
		if(obj instanceof JButton)
		  ListenerEvent(((JButton) obj).getName());
	}
	
	private void ListenerEvent(String event){
		if (event.compareTo("Aceptar") == 0){
			System.out.println("codigooooooooo"+view.getCod());
	
			System.out.println("nombreeeeeeeee"+view.getNom());
			System.out.println("codigo facultaddddd"+view.getCodFacul());			
		
			
			if(CarreraController.existe(view.getCod())){
				JOptionPane.showMessageDialog(null, "EL codigo de carrera ya existe");
			}else if (!FacultadController.existe(view.getCodFacul())){
				JOptionPane.showMessageDialog(null, "El codigo de facultad no existe");
			}else{
				Carrera a=new Carrera();
				a.setCodFacultad(view.getCodFacul());
				a.setCodigo(view.getCod());
				a.setNombre(view.getNom());
				CarreraController.saveCarrera(a);
				System.out.println(view.getCod());
				System.out.println(view.getCod());
				System.out.println(view.getNom());
				System.out.println(view.getCodFacul());			
				view.setCod();
				view.setCodFacul();
				view.setNom();
				JOptionPane.showMessageDialog(null, "Datos guardados con exito");
			}
		}else if(event.compareTo("Cancelar") == 0)
			view.dispose();
	}
}	